package cn.besbing.server.service.primary;

import cn.besbing.model.entities.primary.*;
import cn.besbing.model.mapper.primary.CProjTaskMapper;
import cn.besbing.model.utils.PageDataResult;
import cn.besbing.model.utils.SearchDTO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Xiamen HLYY Network Technology Co., Ltd.
 * DataLoader Cloud
 *
 * @Author sheny
 * @Date 2020/10/16  14:24
 * @Version 1.0
 * @Site https://besbing.cn
 * @Address Xiamen Bazaar U.S. District, 326 South Road, A Dong A209.
 */

@Service
public class PrimaryCProjTaskCoreServiceImpl implements CProjTaskMapper{

    @Autowired(required = false)
    private CProjTaskMapper projTaskMapper;

    @Transactional(rollbackFor = Exception.class)
    public List<CProjTask> getAllTask(SearchDTO searchDTO){
        List<CProjTask> list = new ArrayList<CProjTask>();
        PageHelper.startPage(searchDTO.getPage(), searchDTO.getLimit(),true);
        if(searchDTO.getKeyword() != null){
            list = projTaskMapper.selectAllTask(searchDTO.getKeyword().toString());
        }else {
            list = projTaskMapper.selectAllTask(null);
            //list = permissionMapper.selectByExample(null);
        }
        return list;
    }

    public List<ListObject> getTestConditionsByTaskid(String taskId){
        return projTaskMapper.selectSortList(taskId);
    }

    public CProjTask selectSingleTaskInfoById(String taskId) {
        return projTaskMapper.selectSingleTaskById(taskId);
    }

    public PageDataResult getTask(SearchDTO searchDTO){

        PageDataResult pdr = new PageDataResult();
        PageHelper.startPage(searchDTO.getPage(), searchDTO.getLimit(),true);
        List<TableTaskFields> list = new ArrayList<TableTaskFields>();
        //如果keyword不为null时再传有参的
        if(searchDTO.getKeyword() != null){
            list = projTaskMapper.selectForTable(searchDTO.getKeyword().toString());
        }else {
            list = projTaskMapper.selectForTable(null);
        }
        PageInfo<TableTaskFields> pageInfo = new PageInfo<>(list);
        pdr.setTotals(Long.valueOf(pageInfo.getTotal()).intValue());
        pdr.setList(list);
        return pdr;
    }

    public CProjTask getTaskEntityById(String taskId){
        return projTaskMapper.selectByTaskId(taskId);
    }

    public int setTaskStatusById(CProjTask cProjTask){
        return projTaskMapper.updateByTaskId(cProjTask);
    }

    /**
     * 技术工程师分页表格
     * @param searchDTO
     * @return
     */
    public PageDataResult getTechEngineerTask(SearchDTO searchDTO){

        PageDataResult pdr = new PageDataResult();
        PageHelper.startPage(searchDTO.getPage(), searchDTO.getLimit(),true);
        List<TechEngineerTable> list = new ArrayList<TechEngineerTable>();
        //如果keyword不为null时再传有参的
        if(searchDTO.getKeyword() != null){
            list = projTaskMapper.selectForTechEngineer(searchDTO.getKeyword().toString());
        }else {
            list = projTaskMapper.selectForTechEngineer(null);
        }
        PageInfo<TechEngineerTable> pageInfo = new PageInfo<>(list);
        pdr.setTotals(Long.valueOf(pageInfo.getTotal()).intValue());
        pdr.setList(list);
        return pdr;
    }


    public List<CProjTask> getTaskForReport(String taskid){
        return projTaskMapper.selectByTaskIdForReport(taskid);
    }


    @Override
    public List<TableTaskFields> selectForTable(String taskid) {
        return projTaskMapper.selectForTable(taskid);
    }

    @Override
    public List<TechEngineerTable> selectForTechEngineer(String taskid) {
        return projTaskMapper.selectForTechEngineer(taskid);
    }

    @Override
    public CProjTask selectByTaskId(String taskid) {
        return projTaskMapper.selectByTaskId(taskid);
    }

    @Override
    public List<CProjTask> selectByTaskIdForReport(String taskid) {
        return projTaskMapper.selectByTaskIdForReport(taskid);
    }

    @Override
    public int updateByTaskId(CProjTask record) {
        return projTaskMapper.updateByTaskId(record);
    }

    @Override
    public long countByExample(CProjTaskExample example) {
        return projTaskMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(CProjTaskExample example) {
        return projTaskMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Long seqNum) {
        return projTaskMapper.deleteByPrimaryKey(seqNum);
    }

    @Override
    public int insert(CProjTask record) {
        return projTaskMapper.insert(record);
    }

    @Override
    public int insertSelective(CProjTask record) {
        return projTaskMapper.insertSelective(record);
    }

    @Override
    public List<CProjTask> selectByExample(CProjTaskExample example) {
        return projTaskMapper.selectByExample(example);
    }

    @Override
    public CProjTask selectByPrimaryKey(Long seqNum) {
        return projTaskMapper.selectByPrimaryKey(seqNum);
    }

    @Override
    public int updateByExampleSelective(CProjTask record, CProjTaskExample example) {
        return projTaskMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(CProjTask record, CProjTaskExample example) {
        return projTaskMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(CProjTask record) {
        return projTaskMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CProjTask record) {
        return projTaskMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<CProjTask> selectAllTask(String taskId) {
        return projTaskMapper.selectAllTask(taskId);
    }

    @Override
    public List<ListObject> selectSortList(String taskId) {
        return projTaskMapper.selectSortList(taskId);
    }

    @Override
    public CProjTask selectSingleTaskById(String taskId) {
        return projTaskMapper.selectSingleTaskById(taskId);
    }
}
